package kokonut.admin;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kokonut.shop.product.TShirtModel;

import persistence.ProductPersistence;

public class UpdateStockServlet extends HttpServlet {
    @Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
              throws IOException {

    	int ref = Integer.parseInt(req.getParameter("ref"));
    	String color = req.getParameter("color");
    	String size = req.getParameter("size");
    	int stock = Integer.parseInt(req.getParameter("stock"));

    	ProductPersistence persistence = new ProductPersistence();
    	TShirtModel model = (TShirtModel)persistence.loadModelByRef(ref);
    	//model.updateStockInfo(ref,size,color,stock);
    	persistence.deleteProductByRef(ref);
    	persistence.saveModel(model);
    	persistence.closePM();

    	resp.sendRedirect("/admin/shopAdmin");
    }

}